var e = require;
var t = module;
var n = exports;
("use strict");
Object.defineProperty(n, "__esModule", { value: !0 }), (n.Effect = void 0);
var o,
  c = e("EventConst"),
  x = e("EventManager"),
  t =
    ((i.prototype.showEffect = function (e, r, y) {
      var a = this;
      void 0 === y && (y = 0), (e = 50 < (e = void 0 === e ? 50 : e) ? 50 : e);
      var t = "prefab/item/Power",
        s = o.power;
      y && ((t = "prefab/item/Key"), (s = o.key));
      for (var n = 0; n < e; ++n)
        this.getNode(s, t).then(function (t) {
          var e,
            n,
            o,
            i = r;
          i &&
            cc.isValid(i) &&
            ((e = cc.find("Canvas")),
            (t.parent = e),
            (o = cc.find("Canvas").getChildByName("Main Camera")),
            (o = e.convertToNodeSpaceAR(
              o.parent.convertToWorldSpaceAR(o.position)
            )),
            (n = e.convertToNodeSpaceAR(
              i.parent.convertToWorldSpaceAR(i.position)
            )),
            (o = cc.v3(
              200 * Math.random() - 100 + o.x,
              200 * Math.random() - 100 + o.y,
              0
            )),
            (t.position = o),
            t.stopAllActions(),
            (t.opacity = 0),
            (t.zIndex = cc.macro.MAX_ZINDEX),
            setTimeout(function () {
              var e;
              i &&
                cc.isValid(i) &&
                ((e = cc.moveTo(1, cc.v2(n.x, n.y))),
                t.runAction(
                  cc.sequence(
                    cc.spawn(
                      cc.fadeIn(0.1),
                      cc.moveBy(0.1, 0, 15).easing(cc.easeBackIn())
                    ),
                    cc.delayTime(0.05),
                    e.easing(cc.easeBackIn()),
                    cc.callFunc(function () {
                      var e = r;
                      e && cc.isValid(e)
                        ? (a.putNode(s, t),
                          e.stopAllActions(),
                          (e.scale = 0.7),
                          x.Event.emit(c.default.POWER_UPDATE),
                          y && x.Event.emit(c.default.KEY_UPDATE),
                          cc
                            .tween(e)
                            .to(
                              0.3,
                              { scale: 1 },
                              { easing: cc.easing.backOut }
                            )
                            .start())
                        : a.putNode(s, t);
                    })
                  )
                ));
            }, 800 * Math.random()));
        });
    }),
    (i.prototype.getNode = function (t, i) {
      var r = this;
      return new Promise(function (n) {
        var o = null,
          e = r.poolMap[t];
        e && e.size()
          ? (((o = e.get()).active = !0),
            console.log("数量充足,从对象池获取<" + o.name + ">"),
            n(o))
          : cc.resources.load("" + i, function (e, t) {
              return e
                ? cc.error(e)
                : (cc.log("加载预制成功", "" + i),
                  ((o = cc.instantiate(t)).active = !0),
                  console.log("数量不足,创建<" + o.name + ">"),
                  void n(o));
            });
      });
    }),
    (i.prototype.putNode = function (e, t) {
      t.active = !1;
      var n = this.poolMap[e];
      n ? n.put(t) : ((n = new cc.NodePool()), (this.poolMap[e] = n).put(t));
    }),
    (i.prototype.clear = function (e) {
      this.poolMap[e].clear(), delete this.poolMap[e];
    }),
    i);
function i() {
  this.poolMap = {};
}
((e = o = o || {}).power = "power"), (e.key = "key"), (n.Effect = new t());
